Repository navigation
Deny find's -exec/-execdir/-ok/-okdir/-delete regardless of allowlist - #1
Merged
DavidLiedle merged 1 commit intoSep 18, 2026
Conversation
…wlist
The default read-only allowlist includes "find **", which matches every
argument after find, including find's own action flags. find . -exec
sh -c '...' + runs an arbitrary program per matched file, independent
of the allowlisted command itself, and does not require a shell
metacharacter (the +-terminated form has no ; in it).
Adds these as single-token entries to the existing hard denylist
(checked before allowlist matching, per this module's own documented
design) rather than a two-token "find -exec" sequence, so the rejection
also catches the realistic case where other predicates sit between find
and the action flag, e.g. find /tmp -type f -exec rm {} +.
Adds regression tests for the +-terminated bypass specifically (proving
the rejection does not merely depend on the existing semicolon check)
and for -delete.
Contributor
|
Thanks for this, and for the careful write-up. You're right: |
DavidLiedle
added a commit
that referenced
this pull request
Sep 18, 2026
Extends the hard denylist beyond find's -exec family (#1): - find: -fprint, -fprint0, -fprintf, -fls write arbitrary files anywhere on disk; cwd containment only covers the working directory. - rg --pre CMD runs CMD for every searched file. - git diff/log/show --output=PATH writes to PATH. - tree -o / --output writes to PATH (including bundled -ao). Program-specific flags are matched against the basename of the first token so they don't collide with unrelated uses (grep -o, rg --pretty). Also applies rustfmt to the tests added in #1 so `cargo fmt --check` passes on main again.
DavidLiedle
added a commit
that referenced
this pull request
Sep 18, 2026
#2) Extends the hard denylist beyond find's -exec family (#1): - find: -fprint, -fprint0, -fprintf, -fls write arbitrary files anywhere on disk; cwd containment only covers the working directory. - rg --pre CMD runs CMD for every searched file. - git diff/log/show --output=PATH writes to PATH. - tree -o / --output writes to PATH (including bundled -ao). Program-specific flags are matched against the basename of the first token so they don't collide with unrelated uses (grep -o, rg --pretty). Also applies rustfmt to the tests added in #1 so `cargo fmt --check` passes on main again.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The default
platform_defaults()read-only allowlist (src/allowlist.rs) includesfind **, which, per the documented glob semantics, matches every token afterfind, includingfind's own action flags.find . -exec sh -c '...' +runs an arbitrary program once per matched file (or once per batch, for the+-terminated form), independent of and unaffected by any allowlist rule forfinditself. Execution goes straight toargv(no shell), so this is not a shell-metacharacter problem:-exec's own+-terminated form has no;in it, so it is not caught by the existingcheck_metacharacterspass either.Fix
Adds
-exec,-execdir,-ok,-okdir, and-deleteas single-token entries to the existing hard denylist insrc/safety.rs(checked before allowlist matching, per this module's own documented design: "a hard denylist of token patterns that no allowlist can re-enable"). Single tokens rather than a two-token["find", "-exec"]sequence, so the rejection also catches the realistic case where other predicates sit betweenfindand the action flag, e.g.find /tmp -type f -exec rm {} +.Tests
Added two regression tests:
find_exec_family_is_always_denied_even_with_predicates_between, using the+-terminated form specifically, to prove the rejection does not merely piggyback on the existing semicolon check.find_ok_family_is_denied_defense_in_depth, for-ok/-okdir(these only support the;-terminated form, so they're already caught earlier bycheck_metacharacterstoday; the denylist entries are belt-and-suspenders in case that changes).plain_find_without_action_flags_is_not_denied_by_hard_denylist, confirming ordinaryfindusage is unaffected.Ran the full suite locally (
cargo test --lib, GNU toolchain): 31 passed, 0 failed, including the new ones above.If this is useful, a mention or link back to my GitHub profile (github.com/holistis) would be appreciated.